import Vue from 'vue'
import App from './App'
import router from "./router"
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import Qs from 'qs'
import ElementUI from 'element-ui';
import constant from './api/constant'

import 'element-ui/lib/theme-chalk/index.css';

import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import {
  BootstrapVue,
  IconsPlugin
} from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
Vue.prototype.$constant = constant;

Vue.use(BootstrapVue)
Vue.use(IconsPlugin)
Vue.use(VueQuillEditor)


Vue.use(router)
Vue.use(ElementUI)
Vue.use(VueAxios, axios)
Vue.use(Qs)
Vue.config.productionTip = false;


axios.defaults.withCredentials = true; //允许跨域
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

// 路由跳转之前
router.beforeEach((to, from, next) => {
  let userLogin = sessionStorage.getItem('userLogin');
  //注销
  if (to.path == '/user/logout') {
    //清空
    sessionStorage.clear();
    //跳转到登录页面
    next({
      path: '/user/login'
    });
  } else if (to.path == '/user/login') {
    //判断时候为空，不为空跳转到首页
    if (userLogin != null) {
      next({
        path: '/user/'
      });
    }
  } else if (to.path == '/user/register') {
    //判断时候为空，不为空跳转到首页
    if (userLogin != null) {
      next({
        path: '/user/'
      });
    }
  } else if (userLogin == null) {
    next({
      path: '/user/login'
    });
  }
  // function a() {
  //   sessionStorage.clear();
  // }
  // setTimeout(a(),43200);
  next();
})
new Vue({
  el: '#app',
  store,
  router,
  render: h => h(App)
})
